home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 11 / FM Towns Free Software Collection 11.iso / t_os / tool / artemis1 / src / cmdview.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-11  |  6.5 KB  |  310 lines

  1. /*
  2.     ARTemis (Graphic Editor for FM-TOWNS)
  3.     (c) MATSUUCHI Ryosuke 1992,1993
  4.  
  5.     cmdview.c
  6. */
  7.  
  8.  
  9. #include <stdio.h>
  10. #include <msdos.cf>
  11. #include <memory.h>
  12.  
  13. #include "ge.h"
  14. #include "dispman.h"
  15. #include "imageman.h"
  16.  
  17. #if 0
  18.  
  19.  
  20.  
  21. #define    MAXLINBYTES        8192    /* 1ライン分のデータの最大バイト数 */
  22. #define    VRAMSEL    0x104
  23.  
  24.  
  25. #define    _GetNewDW    3
  26. #define    _Shift4bit    2
  27. #define    _Store4bit    1
  28. #define    _Shift8bit    4
  29. #define    _Shift12bit    5
  30. #define    _Shift16bit    6
  31. #define    _Store8bit    7
  32. #define    _Store12bit    8
  33. #define    _Shift20bit    9
  34. #define    _Shift24bit    10
  35.  
  36.  
  37. static void makeViewCmd(char *cmdbuf, int dstlen, int srclen)
  38. // 1ライン分の圧縮のコマンドリストを作成する
  39. {
  40.     char  *cp;  int  predw_x, x;
  41.     if (dstlen <= 1)
  42.     {
  43.         cmdbuf[0] = _GetNewDW;
  44.         cmdbuf[1] = _Store4bit;
  45.         cmdbuf[2] = 0;
  46.         return;
  47.     }
  48.     cp = cmdbuf;
  49.     predw_x = -8;
  50.     for (x=0; x<dstlen; x++)
  51.     {
  52.         int sx;
  53.         sx = ((srclen-1) * x + (dstlen-1)/2) / (dstlen-1);
  54.         while ((predw_x/8) < (sx/8))
  55.         {
  56.             *cp++ = _GetNewDW;
  57.             predw_x = (predw_x+8) - (predw_x+8)%8;
  58.         }
  59.         while (predw_x < sx)
  60.         {
  61.             if ((predw_x % 8)==7)
  62.             {
  63.                 *cp++ = _GetNewDW;
  64.             }
  65.             else
  66.             {
  67.                 if (cmdbuf<cp)
  68.                 {
  69.                     switch (*(cp-1)) {
  70.                     case _Shift4bit:
  71.                         *(cp-1) = _Shift8bit;
  72.                         break;
  73.                     case _Shift8bit:
  74.                         *(cp-1) = _Shift12bit;
  75.                         break;
  76.                     case _Shift12bit:
  77.                         *(cp-1) = _Shift16bit;
  78.                         break;
  79.                     case _Shift16bit:
  80.                         *(cp-1) = _Shift20bit;
  81.                         break;
  82.                     case _Shift20bit:
  83.                         *(cp-1) = _Shift24bit;
  84.                         break;
  85.                     default:
  86.                         *cp++ = _Shift4bit;
  87.                     }
  88.                 }
  89.                 else
  90.                     *cp++ = _Shift4bit;
  91.             }
  92.             predw_x++;
  93.         }
  94.         if ((cmdbuf < cp)  &&  (x % 8 < 7)  &&  *(cp-1) == _Store4bit)
  95.             *(cp-1) = _Store8bit;
  96.         else if ((cmdbuf < cp)  &&  (x % 8 < 7)  &&  *(cp-1) == _Store8bit)
  97.             *(cp-1) = _Store12bit;
  98.         else
  99.             *cp++ = _Store4bit;
  100.         if ((predw_x % 8) == 7 && x<dstlen-1)
  101.             *cp++ = _GetNewDW;
  102.         predw_x++;
  103.     }
  104.     *cp = 0;
  105.     return;
  106. }
  107.  
  108.  
  109. void commandView()
  110. {
  111.     eraseLattice_all();
  112.     page_edit();
  113.     gdsploc(0,0);
  114.     if (scrmode != 10 && (editXlen > 640 || editYlen > 480))
  115.     {
  116.         gscrzoom(1,1);
  117.         int xrate,yrate;
  118.         xrate = (editXlen<<10)/640;
  119.         yrate = (editYlen<<10)/480;
  120.         if (xrate < yrate)
  121.         {
  122.             char cmd[8192];
  123.             makeViewCmd(cmd, 640, editXlen);
  124. #if 0
  125.             for (int y=0; y<480; y++)
  126.             {
  127.                 char linebuf[MAXLINBYTES],dspbuf[640/2];
  128.                 memcpy( linebuf, ebuf_adrs(0,((editYlen-1)*y) / (480-1)),
  129.                         _min(MAXLINBYTES,editXlen/2));
  130.                 // grboxfill(0,y,640,1,15,DrawNORMAL);
  131.                 viewscr_sub(VRAMSEL,0x40000+(1024/2)*y,linebuf,cmd);
  132.             }
  133. #else
  134.             for (int yy=0; yy<480; yy+=20)
  135.             {
  136.                 char outbuf[8192];
  137.                 memset(outbuf,0,8192);
  138.                 for (int y=0; y<20; y++)
  139.                 {
  140.                     char linebuf[MAXLINBYTES];
  141.                     memcpy( linebuf,
  142.                             ebuf_adrs(0, ((editYlen-1) * (yy+y)) / (480-1)),
  143.                             _min(MAXLINBYTES, editXlen/2));
  144.                     viewscr_down(outbuf+320*y, linebuf, cmd);
  145.                 }
  146.                 ARTgputblk(0,yy,640,20,outbuf);
  147.             }
  148. #endif
  149.             page_menu();
  150.             int msx,msy;
  151.             msx = ms.x;
  152.             msy = ms.y;
  153.             for (;;)
  154.             {
  155.                 ms_get(&ms);
  156.                 ms.x = msx;
  157.                 ms.y = msy;
  158.                 mous_setpos(&ms,ms.x,ms.y);
  159.                 if (ms.btn1==OFFON || ms.btn2==OFFON || key_read()!=0)
  160.                     break;
  161.             }
  162.             page_edit();
  163.             int vadrs = 0x40000;    // ページ1のVRAMアドレス
  164.             int x_cnt = (scrmode == 10 ? v_editXlen*2 : v_editXlen/2);
  165.             int Bystep = (scrmode == 10 ? editXlen*2 : editXlen/2);
  166.             xymemcpy(VRAMSEL,vadrs,getds(),(int)ebuf_adrs(v_editX,v_editY),
  167.                      x_cnt, v_editYlen, x_cnt, Bystep);
  168.         }
  169.     }
  170.     else if (scrmode == 10 && (320 < editXlen && editXlen <= 640) &&
  171.              (240 < editYlen && editYlen <= 480))
  172.     {
  173.         ebuf_store();
  174.         gscrzoom(2,2);
  175.         grboxfill(0,0,320,240,0,DrawNORMAL);
  176.         //
  177.         {
  178.             int linsiz = ebuf_getlinesize();
  179.             int x,y; char *p;
  180.             for (y=0; y<editYlen/2; y++)
  181.             {
  182.                 char glinbuf[512];
  183.                 p = ebuf_adrs(0,y*2);
  184.                 for (x=0; x<editXlen/2; x++,p+=4)
  185.                 {
  186.                     int r,g,b,c1,c2,c3,c4;
  187.                     c1 = *(short*)p;          c2 = *(short*)(p+2);
  188.                     c3 = *(short*)(p+linsiz); c4 = *(short*)(p+linsiz+2);
  189.                     r = (getR(c1) + getR(c2) + getR(c3) + getR(c4) + 2) / 4;
  190.                     g = (getG(c1) + getG(c2) + getG(c3) + getG(c4) + 2) / 4;
  191.                     b = (getB(c1) + getB(c2) + getB(c3) + getB(c4) + 2) / 4;
  192.                     *(short*)(glinbuf+x*2) = g*1024+r*32+b;
  193.                 }
  194.                 grp_putblk((320-editXlen/2)/2,y,256,1,glinbuf,DrawNORMAL);
  195.             }
  196.         }
  197.         //
  198.         page_menu();
  199.         int msx,msy;
  200.         msx = ms.x;
  201.         msy = ms.y;
  202.         for (;;)
  203.         {
  204.             ms_get(&ms);
  205.             ms.x = msx;
  206.             ms.y = msy;
  207.             mous_setpos(&ms,ms.x,ms.y);
  208.             if (ms.btn1==OFFON || ms.btn2==OFFON || key_read()!=0)
  209.                 break;
  210.         }
  211.         page_edit();
  212.         ebuf_disp();
  213.     }
  214.     else if (scrmode == 10 && (editXlen > 320 || editYlen > 240))
  215.     {
  216.         ebuf_store();
  217.         gscrzoom(2,2);
  218.         int xr,yr,xlen,ylen;
  219.         xr = (editXlen*65536)/320;
  220.         yr = (editYlen*65536)/240;
  221.         if (xr > yr)
  222.             xlen = 320,  ylen = (320*editYlen) / editXlen;
  223.         else
  224.             ylen = 240,  xlen = (240*editXlen) / editYlen;
  225.         grboxfill(0,0,320,240,0,DrawNORMAL);
  226.         zoomcopy(0,0,editXlen-1,editYlen-1,0,0,xlen-1,ylen-1,NO);
  227.         page_menu();
  228.         int msx,msy;
  229.         msx = ms.x;
  230.         msy = ms.y;
  231.         for (;;)
  232.         {
  233.             ms_get(&ms);
  234.             ms.x = msx;
  235.             ms.y = msy;
  236.             mous_setpos(&ms,ms.x,ms.y);
  237.             if (ms.btn1==OFFON || ms.btn2==OFFON || key_read()!=0)
  238.                 break;
  239.         }
  240.         page_edit();
  241.         ebuf_disp();
  242.     }
  243.     else
  244.     {
  245.         if (scrmode == 10)
  246.             gscrzoom(2,2);
  247.         else
  248.             gscrzoom(1,1);
  249.  
  250.         page_menu();
  251.         int msx,msy;
  252.         msx = ms.x;
  253.         msy = ms.y;
  254.         for (;;)
  255.         {
  256.             ms_get(&ms);
  257.             ms.x = msx;
  258.             ms.y = msy;
  259.             mous_setpos(&ms,ms.x,ms.y);
  260.             if (ms.btn1==OFFON || ms.btn2==OFFON || key_read()!=0)
  261.                 break;
  262.         }
  263.         page_edit();
  264.     }
  265.     gscrzoom(zoomX,zoomY);
  266.     gdsploc(dispX,dispY);
  267.     page_menu();
  268.     drawLattice_all();
  269. }
  270.  
  271.  
  272. /* end of cmdview.c */
  273. #else
  274.  
  275. void commandView()
  276. {
  277.     int zr = DMimage_getzoomrate();
  278.     bool lat1disp,lat2disp;
  279.     int dispx,dispy;
  280.     DMimage_getlatticeswitch(&lat1disp,&lat2disp);
  281.     DMimage_getdispxy(&dispx,&dispy);
  282.     DMimage_setlatticeswitch(NO,NO);
  283.     DMimage_setdispxy(0,0);
  284.     DMimage_setzoomrate(minzoomrate);
  285.     int msx,msy;
  286.     msx = ms.x, msy = ms.y;
  287.     mous_setpos(&ms,0,0);
  288.     for (;;)
  289.     {
  290.         for (;;)
  291.         {
  292.             ms_get(&ms);
  293.             if (ms.dx!=0||ms.dy!=0||ms.btn1!=OFF||ms.btn2!=OFF||key_chk()!=0)
  294.                 break;
  295.         }
  296.         DMimage_setdispxy(ms.x,ms.y);
  297.         int tx,ty;
  298.         DMimage_getdispxy(&tx,&ty);
  299.         mous_setpos(&ms,tx,ty);
  300.         if (ms.btn1==OFFON || ms.btn2==OFFON || key_read()!=0)
  301.             break;
  302.     }
  303.     mous_setpos(&ms,msx,msy);
  304.     DMimage_setzoomrate(zr);
  305.     DMimage_setdispxy(dispx,dispy);
  306.     DMimage_setlatticeswitch(lat1disp,lat2disp);
  307. }
  308.  
  309. #endif
  310.